<?php

namespace app\common\validate;

use think\Validate;

class AdminValidate extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...].
     *
     * @var array
     */
    protected $rule = [
        'id|编号' => 'require|number|gt:0',
        'keyword|搜索内容' => 'min:2',
        'roles_list|角色列表' => 'require',
        'account|账号' => 'require|unique:admin',
        'password|密码' => 'require',
        'name|姓名' => 'require|chs|unique:admin',
        'email|邮箱' => 'require|email',
        'mobile|电话' => 'require|mobile|unique:admin',
        'page|页数' => 'require|number|gt:0',
        'limit|分页大小' => 'require|number|gt:5',
        'roles_list|授权角色列表' => 'require',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'.
     *
     * @var array
     */
    protected $message = [];
    protected $scene = [
        'saveAdd' => ['account', 'password', 'name', 'mobile', 'email'],
        'saveEdit' => ['id'],
        'getListPage' => ['page', 'limit', 'keyword'],
        'saveInfo' => ['name', 'email', 'mobile'],
        'setPassword' => ['password'],
        'getRow' => ['id'],
        'savePower' => ['id', 'roles_list'],
    ];

    // edit 验证场景定义
    public function sceneLogin()
    {
        return $this->only(['account', 'password'])
              ->remove('account', 'unique');
    }

    public function sceneSaveInfo()
    {
        return $this->only(['name', 'email', 'mobile'])
              ->remove('mobile', 'unique')->remove('name', 'unique');
    }
}
